package com.ruoyi.lclook.utils;

import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author Choi
 * @Date 2021/7/17
 */


public class ResponseUtils {

    /**
     * 图片路径
     */
    public static String imageUrl(String image) {
        HttpServletRequest request = ServletUtils.getRequest();
        String domain = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
        return image.length() > 0 ? domain + image : "";
    }

    /**
     * 图片组路径
     */
    public static List<String> imagesUrl(String image) {
        List<String> list = StringUtils.str2List(image, ",", true, true);
        int length = list.size();
        for (int i = 0; i < length; i++) {
            list.set(i, ResponseUtils.imageUrl(list.get(i)));
        }
        return list;
    }
}
